module Component {
	export class LoadingUI extends egret.DisplayObjectContainer{
		private _progressUI:egret.Shape;
		private _progressText:egret.TextField;
		private _tipText:egret.TextField;
		public _current:number;
		public _total:number;

		/**
		 * 构造函数
		 */
		public constructor(current:number,total:number) {
			super();
			this._current=current;
			this._total=total;
			this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
		}

		/**
		 * 添加到舞台监听器
		 */
		private onAddToStage(event: egret.Event) {
			this._progressUI=new egret.Shape();

            this._progressText = new egret.TextField;
			this._progressText.fontFamily="楷体";
			this._progressText.size=36;
			this._progressText.textColor=0xffffff;
			//this._progressText.background=true;
			//this._progressText.backgroundColor=0xcccccc;
			this._progressText.textAlign = egret.HorizontalAlign.CENTER;

			this._tipText = new egret.TextField;
			this._tipText.fontFamily = "宋体";
			this._tipText.size = 32;
			this._tipText.textColor = 0xffff00;
			this._tipText.textAlign = egret.HorizontalAlign.CENTER;

			this._progressText.width=this.stage.stageWidth*.8;
			this._progressText.x=-this._progressText.width/2;
			this._progressText.y=-50;
			this._tipText.width=this.stage.stageWidth*.8;
			this._tipText.x=-this._tipText.width/2;
			this._tipText.y=-100;

			this.addChild(this._progressUI);
			this.addChild(this._progressText);
			this.addChild(this._tipText);

			this.drawProgress();
			this.setTipText("开始加载资源···");
		}

		/**
		 * 绘制进度
		 */
		private drawProgress():void{
			this._progressUI.graphics.clear();
			this._progressUI.graphics.lineStyle(1,0x000000);
			this._progressUI.graphics.drawRect(-250,0,500,30);
			this._progressUI.graphics.beginFill(0x0000ff);
			this._progressUI.graphics.drawRect(-250,0,this._current/this._total*500,30);
			this._progressUI.graphics.endFill();
			this._progressText.text=this._current+"/"+this._total+"		"+Math.floor(100*this._current/this._total)+"%";
		}

		/**
		 * 设置提示信息
		 */
		public setTipText(value:string):void{
			this._tipText.text=value;
		}

		/**
		 * 设置进度
		 */
		public setProgress(current:number,total:number):void{
			this._current=current;
			this._total=total;
			this.drawProgress();
		}
	}
}